package dev.alm.alertagentservice.controller;

import dev.alm.alertagentservice.AlertAgentServiceApplication;
import dev.alm.alertagentservice.agent.AlertAgent;
import dev.alm.alertagentservice.bean.ChatForm;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("ai")
@CrossOrigin
public class AiController {

    @Resource
    private AlertAgent alertAgent;

    @PostMapping("chat")
    public String chat(@RequestBody ChatForm chatForm) {
        AlertAgentServiceApplication.TOKEN = chatForm.getToken();
        return alertAgent.chat(chatForm.getMemoryId(), chatForm.getMessage());
    }

    @RequestMapping(value = "stream", produces = "text/stream;charset=utf-8")
    public Flux<String> stream(@RequestBody ChatForm chatForm) {
        AlertAgentServiceApplication.TOKEN = chatForm.getToken();
        return alertAgent.stream(chatForm.getMemoryId(), chatForm.getMessage());
    }


}
